package controller

import (
	"tesou.io/platform/poem-parent/poem-api/common/base"
	"tesou.io/platform/poem-parent/poem-api/common/base/pojo"
	"tesou.io/platform/poem-parent/poem-api/module/core/vo"
	"tesou.io/platform/poem-parent/poem-core/common/base/controller"
	"tesou.io/platform/poem-parent/poem-core/module/core/service"
	"time"
)


type ListController struct {
	controller.BaseController
	service.ListService
}

/**
分页查询
*/
func (this *ListController) Page() {
	data := &vo.ListVO{}
	page := this.GetPage()

	//仍需处理
	dataList := make([]vo.ListVO, 0)
	err := this.ListService.Page(data, page, &dataList,"")
	resp := new(pojo.Response)
	if nil != err {
		resp.RetCode = -1
		resp.Message = err.Error()
	} else {
		resp.Data = dataList
		resp.Page = page
	}
	this.Data["json"] = resp
	this.ServeJSON()
}

//分词画图 词云 SELECT Word, SUM(Score) AS score_sum,group_concat(Id)  FROM t_fenci GROUP BY Word ORDER BY score_sum desc
func (this *ListController) Ciyun() {
	//dataList := make([]interface{}, 0)
	dataList := make([]DataA, 0)
	//TODO  过去3天
	currentTime := time.Now()
	oldTime := currentTime.AddDate(0, 0, -3).Format("2006-01-02 15:04:05")
	sql := "SELECT Word, SUM(Score) AS ScoreSum,group_concat(ObjectId) as GroupConcatID  FROM t_fenci Where CreateTime>'"+ oldTime +"' GROUP BY Word ORDER BY ScoreSum desc limit 150"
	this.ListService.Find(&dataList, sql)
	base.Log.Info("dataList \r\n",dataList)
	resp := new(pojo.Response)
	if len(dataList)==0 {
		resp.RetCode = -1
		resp.Message = "没有数据"
	} else {
		resp.Data = dataList
	}
	this.Data["json"] = resp
	this.ServeJSON()
}

type DataA struct {
		Word          string `json:"name"`
		ScoreSum      float64 `json:"value"`
		GroupConcatID string `json:"GroupConcatID"`

}

//词云 深专
func (this *ListController) Detail() {
	//仍需处理
	from_id := this.Input().Get("from_id")
	sql := "SELECT * FROM t_list where Id in("+ from_id +")"
	dataList := make([]vo.ListVO, 0)
	this.ListService.Find(&dataList,  sql)
	base.Log.Info("dataList \r\n",dataList)
	resp := new(pojo.Response)
	if len(dataList)==0 {
		resp.RetCode = -1
		resp.Message = "没有数据"
	} else {
		resp.Data = dataList
	}
	this.Data["json"] = resp
	this.ServeJSON()
}

//分页

//导出数据